package com.rpc.dubbo.netty;



import com.rpc.dubbo.publicServiceImpl.HelloServiceImpl;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * @author 何章怀晓 hezhanghuaixiao
 * @version V1.0
 * @desc
 */
public class NettyServerHandler extends SimpleChannelInboundHandler<String> {
 /* @Override
  public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    //获取客户端发送的消息，并调用服务
    System.out.println("msg=" + msg);
    //客户端在调用服务器的api 时，我们需要定义一个协议
    //比如要求，每次发消息时，都必须以某个字符串开头 "HelloService#hello#你好"
    String result = new HelloServiceImpl().hello(msg.toString());
    ctx.writeAndFlush(result);
  }*/

  @Override
  protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
    //获取客户端发送的消息，并调用服务
    System.out.println("msg=" + msg);
    //客户端在调用服务器的api 时，我们需要定义一个协议
    //比如要求，每次发消息时，都必须以某个字符串开头 "HelloService#hello#你好"
    String result = new HelloServiceImpl().hello(msg.toString());
    ctx.writeAndFlush(result);
  }

  @Override
  public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    ctx.close();
  }
}

